---
layout: api-page
title: "Class: ModelResponse"
id: api
---

<main class="api-documentation-page">
  

  
  

  <section>

  <header>
      
      
      
          
            <h2>
            ModelResponse
            </h2>
          
          
      
  </header>

  <article>
      <div class="container-overview">
      
          
<section class="method-section">
    
        

        <h4 class="name section-header function-name" id="ModelResponse"><span class="type-signature"></span>new ModelResponse<span class="signature">()</span><span class="type-signature return-signature"></span></h4>

        
    

        
        <div class="description">
            <p>A ModelResponse is a container for the results of a get, set, or call operation performed on a Model. The ModelResponse provides methods which can be used to specify the output format of the data retrieved from a Model, as well as how that data is delivered.</p>
        </div>
        

    

    

    

    

    




  <dl class="details">

      

      

      

      

      

      

      

      

      

      

      

      

      
      <dt class="tag-source">Source:</dt>
      <dd class="tag-source">
          <a href="response_ModelResponse.js.html">response/ModelResponse.js</a>, <a href="response_ModelResponse.js.html#line5">line 5</a>
      </dd>
      

      

      

      
  </dl>


    

    

    

    

    

    

    
</section>
      
      </div>

      
          <h3 class="subsection-title">Extends</h3>

          


    <ul>
        <li><a href="Observable.html">Observable</a></li>
    </ul>


      

      

      

       

      

      

      
          <h3 class="subsection-title">Methods</h3>

          
              
<section class="method-section">
    
        

        <h4 class="name section-header function-name" id="forEach"><span class="type-signature"></span>forEach<span class="signature">(onNext<span class="signature-attributes">nullable</span>, onError<span class="signature-attributes">nullable</span>, onCompleted<span class="signature-attributes">nullable</span>)</span><span class="type-signature return-signature"> &rarr; {<a href="Subscription.html">Subscription</a>}</span></h4>

        
    

        
        <div class="description">
            <p>The forEach method is a synonym for Observable.prototype.subscribe and triggers the execution of the Observable, causing the values within to be pushed to a callback. An Observable is like a pipe of water that is closed. When forEach is called, we open the valve and the values within are pushed at us.  These values can be received using either callbacks or an Observer object.</p>
        </div>
        

    

    

    

    
        <h5>Parameters:</h5>
        

<div class="parameters-section">
    <table class="params">
        <thead>
        <tr>
            
            <th class="header-name-and-attributes">
              Name
              
                &amp; Attributes
              
            </th>
            

            <th class="header-type">Type</th>

            

            <th class="last header-description">Description</th>
        </tr>
        </thead>

        <tbody>
        

            <tr>
                
                    <td>
                        <span class="name">onNext</span>
                        
                            
                        
                            
                                <br>
                                <span class="attribute">nullable</span>
                            
                        
                            
                        
                    </td>
                

                <td class="type">
                
                    
<span class="param-type"><a href="Observable.html#~onNextCallback">Observable~onNextCallback</a></span>


                
                </td>

                

                <td class="description last"><p>a callback that accepts the next value in the stream of values</p></td>
            </tr>

        

            <tr>
                
                    <td>
                        <span class="name">onError</span>
                        
                            
                        
                            
                                <br>
                                <span class="attribute">nullable</span>
                            
                        
                            
                        
                    </td>
                

                <td class="type">
                
                    
<span class="param-type"><a href="Observable.html#~onErrorCallback">Observable~onErrorCallback</a></span>


                
                </td>

                

                <td class="description last"><p>a callback that accepts an error that occurred while evaluating the operation underlying the <a href="Observable.html">Observable</a> stream</p></td>
            </tr>

        

            <tr>
                
                    <td>
                        <span class="name">onCompleted</span>
                        
                            
                        
                            
                                <br>
                                <span class="attribute">nullable</span>
                            
                        
                            
                        
                    </td>
                

                <td class="type">
                
                    
<span class="param-type"><a href="Observable.html#~onCompletedCallback">Observable~onCompletedCallback</a></span>


                
                </td>

                

                <td class="description last"><p>a callback that is invoked when the <a href="Observable.html">Observable</a> stream has ended, and the <a href="Observable.html#~onNextCallback">Observable~onNextCallback</a> will not receive any more values</p></td>
            </tr>

        
        </tbody>
    </table>
</div>

    

    




  <dl class="details">

      

      

      

      
      <dt class="tag-overrides">Overrides:</dt>
      <dd class="tag-overrides">
          <a href="Observable.html#forEach">Observable#forEach</a>
      </dd>
      

      

      

      

      

      

      

      

      

      
      <dt class="tag-source">Source:</dt>
      <dd class="tag-source">
          <a href="typedefs_Observable.js.html">typedefs/Observable.js</a>, <a href="typedefs_Observable.js.html#line6">line 6</a>
      </dd>
      

      

      

      
  </dl>


    

    

    

    

    

    
    
    
            


<dl class="return-type">
    <dt>
        Return Type: 
    </dt>
    <dd>
        
<span class="param-type"><a href="Subscription.html">Subscription</a></span>


    </dd>
</dl>

        

    
</section>
          
              
<section class="method-section">
    
        

        <h4 class="name section-header function-name" id="progressively"><span class="type-signature"></span>progressively<span class="signature">()</span><span class="type-signature return-signature"> &rarr; {<a href="ModelResponse.html">ModelResponse</a>.&lt;<a href="global.html#JSONEnvelope">JSONEnvelope</a>>}</span></h4>

        
    

        
        <div class="description">
            <p>The progressively method breaks the response up into two parts: the data immediately available in the Model cache, and the data in the Model cache after the missing data has been retrieved from the DataSource.
The progressively method creates a ModelResponse that immediately returns the requested data that is available in the Model cache. If any requested paths are not available in the cache, the ModelResponse will send another JSON message with all of the requested data after it has been retrieved from the DataSource.</p>
        </div>
        

    

    

    

    

    




  <dl class="details">

      

      

      

      

      

      

      

      

      

      

      

      

      
      <dt class="tag-source">Source:</dt>
      <dd class="tag-source">
          <a href="response_ModelResponse.js.html">response/ModelResponse.js</a>, <a href="response_ModelResponse.js.html#line22">line 22</a>
      </dd>
      

      

      

      
  </dl>


    

    

    

    

    

    
    
        <h5>Returns:</h5>
    
    
            
<div class="param-desc">
    <p>the values found at the requested paths.</p>
</div>



<dl class="return-type">
    <dt>
        Return Type: 
    </dt>
    <dd>
        
<span class="param-type"><a href="ModelResponse.html">ModelResponse</a>.&lt;<a href="global.html#JSONEnvelope">JSONEnvelope</a>></span>


    </dd>
</dl>

        

    
        <h5>Example</h5>
        
    <pre class="prettyprint"><code>var dataSource = (new falcor.Model({
  cache: {
    user: {
      name: "Steve",
      surname: "McGuire",
      age: 31
    }
  }
})).asDataSource();

var model = new falcor.Model({
  source: dataSource,
  cache: {
    user: {
      name: "Steve",
      surname: "McGuire"
    }
  }
});

model.
  get(["user",["name", "surname", "age"]]).
  progressively().
  // this callback will be invoked twice, once with the data in the
  // Model cache, and again with the additional data retrieved from the DataSource.
  subscribe(function(json){
    console.log(JSON.stringify(json,null,4));
  });

// prints...
// {
//     "json": {
//         "user": {
//             "name": "Steve",
//             "surname": "McGuire"
//         }
//     }
// }
// ...and then prints...
// {
//     "json": {
//         "user": {
//             "name": "Steve",
//             "surname": "McGuire",
//             "age": 31
//         }
//     }
// }</code></pre>

    
</section>
          
              
<section class="method-section">
    
        

        <h4 class="name section-header function-name" id="subscribe"><span class="type-signature"></span>subscribe<span class="signature">(onNext<span class="signature-attributes">nullable</span>, onError<span class="signature-attributes">nullable</span>, onCompleted<span class="signature-attributes">nullable</span>)</span><span class="type-signature return-signature"> &rarr; {<a href="Subscription.html">Subscription</a>}</span></h4>

        
    

        
        <div class="description">
            <p>The subscribe method is a synonym for Observable.prototype.forEach and triggers the execution of the Observable, causing the values within to be pushed to a callback. An Observable is like a pipe of water that is closed. When forEach is called, we open the valve and the values within are pushed at us.  These values can be received using either callbacks or an Observer object.</p>
        </div>
        

    

    

    

    
        <h5>Parameters:</h5>
        

<div class="parameters-section">
    <table class="params">
        <thead>
        <tr>
            
            <th class="header-name-and-attributes">
              Name
              
                &amp; Attributes
              
            </th>
            

            <th class="header-type">Type</th>

            

            <th class="last header-description">Description</th>
        </tr>
        </thead>

        <tbody>
        

            <tr>
                
                    <td>
                        <span class="name">onNext</span>
                        
                            
                        
                            
                                <br>
                                <span class="attribute">nullable</span>
                            
                        
                            
                        
                    </td>
                

                <td class="type">
                
                    
<span class="param-type"><a href="Observable.html#~onNextCallback">Observable~onNextCallback</a></span>


                
                </td>

                

                <td class="description last"><p>a callback that accepts the next value in the stream of values</p></td>
            </tr>

        

            <tr>
                
                    <td>
                        <span class="name">onError</span>
                        
                            
                        
                            
                                <br>
                                <span class="attribute">nullable</span>
                            
                        
                            
                        
                    </td>
                

                <td class="type">
                
                    
<span class="param-type"><a href="Observable.html#~onErrorCallback">Observable~onErrorCallback</a></span>


                
                </td>

                

                <td class="description last"><p>a callback that accepts an error that occurred while evaluating the operation underlying the <a href="Observable.html">Observable</a> stream</p></td>
            </tr>

        

            <tr>
                
                    <td>
                        <span class="name">onCompleted</span>
                        
                            
                        
                            
                                <br>
                                <span class="attribute">nullable</span>
                            
                        
                            
                        
                    </td>
                

                <td class="type">
                
                    
<span class="param-type"><a href="Observable.html#~onCompletedCallback">Observable~onCompletedCallback</a></span>


                
                </td>

                

                <td class="description last"><p>a callback that is invoked when the <a href="Observable.html">Observable</a> stream has ended, and the <a href="Observable.html#~onNextCallback">Observable~onNextCallback</a> will not receive any more values</p></td>
            </tr>

        
        </tbody>
    </table>
</div>

    

    




  <dl class="details">

      

      

      

      
      <dt class="tag-overrides">Overrides:</dt>
      <dd class="tag-overrides">
          <a href="Observable.html#subscribe">Observable#subscribe</a>
      </dd>
      

      

      

      

      

      

      

      

      

      
      <dt class="tag-source">Source:</dt>
      <dd class="tag-source">
          <a href="typedefs_Observable.js.html">typedefs/Observable.js</a>, <a href="typedefs_Observable.js.html#line17">line 17</a>
      </dd>
      

      

      

      
  </dl>


    

    

    

    

    

    
    
    
            


<dl class="return-type">
    <dt>
        Return Type: 
    </dt>
    <dd>
        
<span class="param-type"><a href="Subscription.html">Subscription</a></span>


    </dd>
</dl>

        

    
</section>
          
      

      

      
  </article>

  </section>
  

  
</main>



        
        <!--
          In case someone comes along later and sees the active item on the
          toc acting weirdly, hopefully they'll see this comment. This page, unlike
          any seen during development, has multiple 'docs' passed to container.tmpl.
          To debug it and enhance the page as needed, I would suggest looking there first.
        -->
        

        <!-- Generate the table of contents -->
        <nav class="table-of-contents api-doc-toc">
            <ul class="nav">
                <li>
                    <a href="DataSource.html">Classes</a>
                    <ul class="toc-api-classes">
                        
                            <li class="toc-api-class ">
                                <a href="DataSource.html" data-target="#DataSource">DataSource</a>
                                
                                

    <ul class="toc-api-subgroup toc-api-subgroup-methods">
        <li>
            <span class="toc-api-subgroup-title">Methods</span>
        </li>
        
            <li class="toc-api-subgroup-item">
                <a href="DataSource.html#call" data-target="#call">call</a>
            </li>
        
            <li class="toc-api-subgroup-item">
                <a href="DataSource.html#get" data-target="#get">get</a>
            </li>
        
            <li class="toc-api-subgroup-item">
                <a href="DataSource.html#set" data-target="#set">set</a>
            </li>
         
    </ul>


                                


                                


                            </li>
                        
                            <li class="toc-api-class ">
                                <a href="FromEsObserverAdapter.html" data-target="#FromEsObserverAdapter">FromEsObserverAdapter</a>
                                
                                


                                


                                


                            </li>
                        
                            <li class="toc-api-class ">
                                <a href="HttpDataSource.html" data-target="#HttpDataSource">HttpDataSource</a>
                                
                                

    <ul class="toc-api-subgroup toc-api-subgroup-methods">
        <li>
            <span class="toc-api-subgroup-title">Methods</span>
        </li>
        
            <li class="toc-api-subgroup-item">
                <a href="HttpDataSource.html#call" data-target="#call">call</a>
            </li>
        
            <li class="toc-api-subgroup-item">
                <a href="HttpDataSource.html#get" data-target="#get">get</a>
            </li>
        
            <li class="toc-api-subgroup-item">
                <a href="HttpDataSource.html#set" data-target="#set">set</a>
            </li>
         
    </ul>


                                


                                


                            </li>
                        
                            <li class="toc-api-class ">
                                <a href="Model.html" data-target="#Model">Model</a>
                                
                                

    <ul class="toc-api-subgroup toc-api-subgroup-methods">
        <li>
            <span class="toc-api-subgroup-title">Methods</span>
        </li>
        
            <li class="toc-api-subgroup-item">
                <a href="Model.html#_setMaxSize" data-target="#_setMaxSize">_setMaxSize</a>
            </li>
        
            <li class="toc-api-subgroup-item">
                <a href="Model.html#asDataSource" data-target="#asDataSource">asDataSource</a>
            </li>
        
            <li class="toc-api-subgroup-item">
                <a href="Model.html#batch" data-target="#batch">batch</a>
            </li>
        
            <li class="toc-api-subgroup-item">
                <a href="Model.html#boxValues" data-target="#boxValues">boxValues</a>
            </li>
        
            <li class="toc-api-subgroup-item">
                <a href="Model.html#call" data-target="#call">call</a>
            </li>
        
            <li class="toc-api-subgroup-item">
                <a href="Model.html#deref" data-target="#deref">deref</a>
            </li>
        
            <li class="toc-api-subgroup-item">
                <a href="Model.html#get" data-target="#get">get</a>
            </li>
        
            <li class="toc-api-subgroup-item">
                <a href="Model.html#getCache" data-target="#getCache">getCache</a>
            </li>
        
            <li class="toc-api-subgroup-item">
                <a href="Model.html#getPath" data-target="#getPath">getPath</a>
            </li>
        
            <li class="toc-api-subgroup-item">
                <a href="Model.html#getVersion" data-target="#getVersion">getVersion</a>
            </li>
        
            <li class="toc-api-subgroup-item">
                <a href="Model.html#invalidate" data-target="#invalidate">invalidate</a>
            </li>
        
            <li class="toc-api-subgroup-item">
                <a href="Model.html#preload" data-target="#preload">preload</a>
            </li>
        
            <li class="toc-api-subgroup-item">
                <a href="Model.html#set" data-target="#set">set</a>
            </li>
        
            <li class="toc-api-subgroup-item">
                <a href="Model.html#setCache" data-target="#setCache">setCache</a>
            </li>
        
            <li class="toc-api-subgroup-item">
                <a href="Model.html#treatErrorsAsValues" data-target="#treatErrorsAsValues">treatErrorsAsValues</a>
            </li>
        
            <li class="toc-api-subgroup-item">
                <a href="Model.html#unbatch" data-target="#unbatch">unbatch</a>
            </li>
        
            <li class="toc-api-subgroup-item">
                <a href="Model.html#unboxValues" data-target="#unboxValues">unboxValues</a>
            </li>
        
            <li class="toc-api-subgroup-item">
                <a href="Model.html#withoutDataSource" data-target="#withoutDataSource">withoutDataSource</a>
            </li>
         
    </ul>


                                

    <ul class="toc-api-subgroup toc-api-subgroup-types">
        <li>
            <span class="toc-api-subgroup-title">Types</span>
        </li>
        
            <li class="toc-api-subgroup-item">
                <a href="Model.html#~comparator" data-target="#\~comparator">comparator</a>
            </li>
        
            <li class="toc-api-subgroup-item">
                <a href="Model.html#~errorSelector" data-target="#\~errorSelector">errorSelector</a>
            </li>
        
            <li class="toc-api-subgroup-item">
                <a href="Model.html#~onChange" data-target="#\~onChange">onChange</a>
            </li>
         
    </ul>


                                


                            </li>
                        
                            <li class="toc-api-class current-page">
                                <a href="ModelResponse.html" data-target="#ModelResponse">ModelResponse</a>
                                
                                

    <ul class="toc-api-subgroup toc-api-subgroup-methods">
        <li>
            <span class="toc-api-subgroup-title">Methods</span>
        </li>
        
            <li class="toc-api-subgroup-item">
                <a href="ModelResponse.html#forEach" data-target="#forEach">forEach</a>
            </li>
        
            <li class="toc-api-subgroup-item">
                <a href="ModelResponse.html#progressively" data-target="#progressively">progressively</a>
            </li>
        
            <li class="toc-api-subgroup-item">
                <a href="ModelResponse.html#subscribe" data-target="#subscribe">subscribe</a>
            </li>
         
    </ul>


                                


                                


                            </li>
                        
                            <li class="toc-api-class ">
                                <a href="ModelResponseObserver.html" data-target="#ModelResponseObserver">ModelResponseObserver</a>
                                
                                


                                


                                


                            </li>
                        
                            <li class="toc-api-class ">
                                <a href="Observable.html" data-target="#Observable">Observable</a>
                                
                                

    <ul class="toc-api-subgroup toc-api-subgroup-methods">
        <li>
            <span class="toc-api-subgroup-title">Methods</span>
        </li>
        
            <li class="toc-api-subgroup-item">
                <a href="Observable.html#forEach" data-target="#forEach">forEach</a>
            </li>
        
            <li class="toc-api-subgroup-item">
                <a href="Observable.html#subscribe" data-target="#subscribe">subscribe</a>
            </li>
         
    </ul>


                                

    <ul class="toc-api-subgroup toc-api-subgroup-types">
        <li>
            <span class="toc-api-subgroup-title">Types</span>
        </li>
        
            <li class="toc-api-subgroup-item">
                <a href="Observable.html#~onCompletedCallback" data-target="#\~onCompletedCallback">onCompletedCallback</a>
            </li>
        
            <li class="toc-api-subgroup-item">
                <a href="Observable.html#~onErrorCallback" data-target="#\~onErrorCallback">onErrorCallback</a>
            </li>
        
            <li class="toc-api-subgroup-item">
                <a href="Observable.html#~onNextCallback" data-target="#\~onNextCallback">onNextCallback</a>
            </li>
         
    </ul>


                                


                            </li>
                        
                            <li class="toc-api-class ">
                                <a href="Subscription.html" data-target="#Subscription">Subscription</a>
                                
                                

    <ul class="toc-api-subgroup toc-api-subgroup-methods">
        <li>
            <span class="toc-api-subgroup-title">Methods</span>
        </li>
        
            <li class="toc-api-subgroup-item">
                <a href="Subscription.html#dispose" data-target="#dispose">dispose</a>
            </li>
         
    </ul>


                                


                                


                            </li>
                        
                            <li class="toc-api-class ">
                                <a href="ToEsSubscriptionAdapter.html" data-target="#ToEsSubscriptionAdapter">ToEsSubscriptionAdapter</a>
                                
                                


                                


                                


                            </li>
                        
                    </ul>
                </li>
                <li class="toc-api-type-list ">
                    <a href="global.html">Global Types</a>
                    <ul class="toc-api-types">
                        
                            <li class="toc-api-type">
                                <a href="global.html#Atom" data-target="#Atom">Atom</a>
                            </li>
                        
                            <li class="toc-api-type">
                                <a href="global.html#JSONEnvelope" data-target="#JSONEnvelope">JSONEnvelope</a>
                            </li>
                        
                            <li class="toc-api-type">
                                <a href="global.html#JSONGraph" data-target="#JSONGraph">JSONGraph</a>
                            </li>
                        
                            <li class="toc-api-type">
                                <a href="global.html#JSONGraphEnvelope" data-target="#JSONGraphEnvelope">JSONGraphEnvelope</a>
                            </li>
                        
                            <li class="toc-api-type">
                                <a href="global.html#Key" data-target="#Key">Key</a>
                            </li>
                        
                            <li class="toc-api-type">
                                <a href="global.html#KeySet" data-target="#KeySet">KeySet</a>
                            </li>
                        
                            <li class="toc-api-type">
                                <a href="global.html#Path" data-target="#Path">Path</a>
                            </li>
                        
                            <li class="toc-api-type">
                                <a href="global.html#PathSet" data-target="#PathSet">PathSet</a>
                            </li>
                        
                            <li class="toc-api-type">
                                <a href="global.html#PathValue" data-target="#PathValue">PathValue</a>
                            </li>
                        
                            <li class="toc-api-type">
                                <a href="global.html#Range" data-target="#Range">Range</a>
                            </li>
                        
                    </ul>
                </li>
            </ul>
        </nav>